home *** CD-ROM | disk | FTP | other *** search
Text File | 2003-07-17 | 61.2 KB | 2,275 lines |
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 08 Nov 2000
- // Author: bwk
- //
- // Description:
- // This script initializes the Channel Box and Layer Editor.
- // Initialization involves determining the initial preferences,
- // creating the UI and setting the initial visibility.
- //
-
- proc createLayerEditor(string $parent)
- //
- // Description:
- // Create the Layer Editor UI.
- //
- // Arguments:
- // $parent - The parent layout. Must be a form layout.
- //
- {
- global string $gCurrentLayerEditor;
-
- // Bail if the parent layout is not the expected type.
- //
- string $requiredType = "formLayout";
- if ($requiredType != `objectTypeUI $parent`) {
- error ("Argument must be a " + $requiredType);
- return;
- }
-
- setParent $parent;
- $gCurrentLayerEditor = $parent;
-
- // Need a menu bar layout for the menus.
- //
- $menuBarLayout = `menuBarLayout`;
-
- // Create Edit menu and items.
- //
- $editMenu = `menu -label "Layers"`;
- $newMenuItem = `menuItem -label "Create Layer"`;
- $deleteMenuItem = `menuItem -label "Delete Selected Layer(s)"
- LayerEditorEditMenuDeleteMenuItem`;
- $layerMenuItem = `menuItem -label "Edit Selected Layer(s)..."
- LayerEditorEditMenuEditMenuItem`;
-
- menuItem -divider true;
- $selectObjectsMenuItem = `menuItem -label "Select Objects in Selected Layer(s)"
- LayerEditorEditMenuSelectObjectsMenuItem`;
- $addObjectsMenuItem = `menuItem -label "Add Selected Objects to Current Layer"
- LayerEditorEditMenuAddObjectsMenuItem`;
- $removeObjectsMenuItem = `menuItem -label "Remove Objects from Selected Layer(s)"
- LayerEditorEditMenuRemoveObjectsMenuItem`;
-
- menuItem -divider true;
- $layerAttributesMenuItem = `menuItem -label "Layer Attributes..."
- LayerEditorEditMenuLayerAttributesMenuItem`;
- $membershipMenuItem = `menuItem -label "Membership..."`;
-
- menuItem -divider true;
- $selectUnusedMenuItem = `menuItem -label "Select Unused Layers"`;
- $removeFromLayerMenuItem = `menuItem -label "Remove Selected Object(s) from Layers"
- LayerEditorEditMenuRemoveFromLayerMenuItem`;
-
- // Create Option menu and items.
- //
- $optionsMenu = `menu -label "Options"`;
- menuItem -checkBox false -label "Make New Layers Current"
- -command ("optionVar -intValue displayLayerCurrent #1;"
- + "optionVar -intValue renderLayerCurrent #1;")
- LayerEditorOptionsMenuMakeCurrentMenuItem;
- menuItem -checkBox false -label "Use Current Layer"
- -command ("editDisplayLayerGlobals -useCurrent #1;"
- + "editRenderLayerGlobals -useCurrent #1;")
- LayerEditorOptionsMenuUseCurrentMenuItem;
-
- // Create form layout for rest of editor.
- //
- $form = `formLayout`;
-
- // Option menu for displaying Display Layers versus Render Layers.
- //
- $optionMenu = `optionMenu LayerEditorTypeOptionMenu`;
- menuItem -label "Display";
- menuItem -label "Render";
-
- // Button for creating new layers.
- //
- $newButton = `symbolButton -image "newlayer.xpm"
- -annotation "Create a new layer"`;
-
- // Tab layout with two children. One for display layers, the other
- // for render layers.
- //
- setParent $form;
- string $tabLayout = `tabLayout -scrollable false -tabsVisible false
- DisplayLayerUITabLayout`;
-
- // Display layers.
- //
- setParent $tabLayout;
- scrollLayout -horizontalScrollBarThickness 0 DisplayLayerTab;
- gridLayout
- -allowEmptyCells false
- -autoGrow true
- -numberOfColumns 1
- -cellWidthHeight 350 20
- LayerEditorDisplayLayerLayout;
-
- // Render layers.
- //
- setParent $tabLayout;
- scrollLayout -horizontalScrollBarThickness 0 RenderLayerTab;
- gridLayout
- -allowEmptyCells false
- -autoGrow true
- -numberOfColumns 1
- -cellWidthHeight 350 20
- LayerEditorRenderLayerLayout;
-
- optionMenu -edit
- -changeCommand ("layerEditorDisplayTypeChange")
- $optionMenu;
-
- formLayout -edit
- -attachForm $optionMenu "top" 1
- -attachForm $optionMenu "left" 1
- -attachNone $optionMenu "bottom"
- -attachControl $optionMenu "right" 0 $newButton
-
- -attachForm $newButton "top" 1
- -attachNone $newButton "left"
- -attachNone $newButton "bottom"
- -attachForm $newButton "right" 1
-
- -attachControl $tabLayout "top" 2 $optionMenu
- -attachForm $tabLayout "left" 0
- -attachForm $tabLayout "bottom" 0
- -attachForm $tabLayout "right" 0
- $form;
-
- formLayout -edit
- -attachForm $menuBarLayout "top" 0
- -attachForm $menuBarLayout "left" 0
- -attachForm $menuBarLayout "bottom" 0
- -attachForm $menuBarLayout "right" 0
- $parent;
-
- // Attach commands to menu items and buttons.
- //
- menu -edit -postMenuCommand ("layerEditorShowEditMenu " + $editMenu) $editMenu;
- menu -edit -postMenuCommand ("layerEditorShowOptionsMenu " + $optionsMenu) $optionsMenu;
-
- menuItem -edit -command ("layerEditorCreateLayer") $newMenuItem;
- menuItem -edit -command ("layerEditorDeleteLayer \"\"") $deleteMenuItem;
- menuItem -edit -command ("layerEditorEditLayer \"\"") $layerMenuItem;
- menuItem -edit -command ("layerEditorSelectObjects \"\"") $selectObjectsMenuItem;
- menuItem -edit -command ("layerEditorAddObjects \"\"") $addObjectsMenuItem;
- menuItem -edit -command ("layerEditorRemoveObjects \"\"") $removeObjectsMenuItem;
- menuItem -edit -command ("layerEditorSelectUnused") $selectUnusedMenuItem;
- menuItem -edit -command ("layerEditorRemoveFromLayer") $removeFromLayerMenuItem;
- menuItem -edit -command ("layerEditorLayerAttributes \"\"") $layerAttributesMenuItem;
- menuItem -edit -command ("layerEditorMembership \"\"") $membershipMenuItem;
-
- symbolButton -edit -command ("layerEditorCreateLayer") $newButton;
-
- // Attach script jobs for detecting when user creates new scene
- // or opens a scene.
- //
- scriptJob -permanent -parent $parent -event NewSceneOpened ("layerEditorNewScene");
- scriptJob -permanent -parent $parent -event SceneOpened ("layerEditorOpenScene");
-
- // Attach a script job that detects creation/deletion of layer nodes.
- //
- scriptJob -permanent -parent $parent -event displayLayerChange ("layerEditorDisplayLayerChange");
- scriptJob -permanent -parent $parent -event renderLayerChange ("layerEditorRenderLayerChange");
- }
-
- proc string getShortName(string $name)
- //
- // Description:
- // Given a full path name to an object return the short name.
- //
- // Arguments:
- // $name - Full path name to an object.
- //
- // Returns:
- // The short name.
- //
- {
- string $result = "", $tokenArray[];
- int $tokenCount;
-
- // To get the short name from a long name tokenize the long name
- // using "|" as the split character because that is the path
- // separator. The short name is simply the last token.
- //
- $tokenCount = `tokenize $name "|" $tokenArray`;
- if (0 < $tokenCount) $result = $tokenArray[$tokenCount - 1];
-
- return $result;
- }
-
- proc int isValidName(string $name)
- //
- // Description:
- // Determine if the given string is potentially a valid name.
- // Note that this procedure does not test to see if the name is
- // unique, it just tests the string characters.
- //
- // Check to ensure that the string does not begin with a number
- // and is followed only by alphanumeric characters or underscores.
- //
- // Arguments:
- // $name - The name.
- //
- // Returns:
- // True if the name is valid, false otherwise.
- //
- {
- int $result = false;
-
- if ("" != $name) {
- //
- // Begins with letter or underscore, followed by
- // letters, digits, or underscores.
- //
- string $regExpr = "([a-zA-Z_]+)([[a-zA-Z0-9_])*";
- string $temp = match($regExpr, $name);
- if ($temp == $name) {
- $result = true;
- }
- }
-
- return $result;
- }
-
- proc string getLayerDisplayType()
- //
- // Description:
- // Return the current type of layer being displayed in the
- // Layer Editor.
- //
- // Returns:
- // "Display" or "Render".
- //
- {
- global string $gCurrentLayerEditor;
-
- string $type = "";
-
- // Verify the current layer editor.
- //
- if ("" == $gCurrentLayerEditor) {
- error ("There is no current Layer Editor");
- return $type;
- }
-
- // Set the parent to the current layer editor. We can now use short
- // names of our controls and be certain they reference the correct
- // control.
- //
- setParent $gCurrentLayerEditor;
-
- // Get the current type of layers being displayed.
- //
- string $type = `optionMenu -query -value LayerEditorTypeOptionMenu`;
-
- if ("Display" == $type) {
- } else if ("Render" == $type) {
- } else {
- error ("Invalid layer type: " + $type);
- }
-
- return $type;
- }
-
- proc string [] getLayerSelection(string $type)
- //
- // Description:
- // Return the current layer selection for the specified layer type.
- //
- // Arguments:
- // $type - Valid values are: "Display", "Render", or
- // an emtpy string. In the case of an empty string the
- // current layer type displayed in the editor will be used.
- //
- // Returns:
- // A string array containing the names of the selected layers.
- //
- {
- global string $gCurrentLayerEditor;
-
- string $selectionArray[];
- string $buttonLayout = "", $button, $buttonArray[];
- int $index = 0;
-
- // If type argument not specified then determine it.
- //
- if ("" == $type) {
- $type = getLayerDisplayType();
- }
-
- // Set the parent to the current layer editor. We can now use short
- // names of our controls and be certain they reference the correct
- // control.
- //
- setParent $gCurrentLayerEditor;
-
- // Get the correct layout of layer buttons depending on the type of
- // layers currently being shown.
- //
- if ("Display" == $type) {
- $buttonLayout = "LayerEditorDisplayLayerLayout";
-
- } else if ("Render" == $type) {
- $buttonLayout = "LayerEditorRenderLayerLayout";
-
- } else {
- error ("Invalid layer type: " + $type);
- return $selectionArray;
- }
-
- // Get all the buttons in the layout.
- //
- $buttonArray = `layout -query -childArray $buttonLayout`;
-
- // For each button check to see if it is selected.
- //
- for ($button in $buttonArray) {
- if (("Display" == $type && `layerButton -query -select $button`)
- || ("Render" == $type && `renderLayerButton -query -select $button`)) {
- $selectionArray[$index++] = $button;
- }
- }
-
- return $selectionArray;
- }
-
- proc string getCurrentLayer(string $type)
- //
- // Description:
- // Return the current layer for the specified layer type.
- //
- // Arguments:
- // $type - Valid values are: "Display", "Render", or
- // an emtpy string. In the case of an empty string the
- // current layer type displayed in the editor will be used.
- //
- // Returns:
- // A string containing the name of the current layer.
- //
- {
- global string $gCurrentLayerEditor;
-
- string $currentLayer = "";
- string $buttonLayout = "", $button, $buttonArray[];
-
- // If type argument not specified then determine it.
- //
- if ("" == $type) {
- $type = getLayerDisplayType();
- }
-
- // Set the parent to the current layer editor. We can now use short
- // names of our controls and be certain they reference the correct
- // control.
- //
- setParent $gCurrentLayerEditor;
-
- // Get the correct layout of layer buttons depending on the type of
- // layers currently being shown.
- //
- if ("Display" == $type) {
- $buttonLayout = "LayerEditorDisplayLayerLayout";
-
- } else if ("Render" == $type) {
- $buttonLayout = "LayerEditorRenderLayerLayout";
-
- } else {
- error ("Invalid layer type: " + $type);
- return $currentLayer;
- }
-
- // Get all the buttons in the layout.
- //
- $buttonArray = `layout -query -childArray $buttonLayout`;
-
- // For each button check to see if it is the current layer.
- //
- for ($button in $buttonArray) {
- if (("Display" == $type && `layerButton -query -current $button`)
- || ("Render" == $type && `renderLayerButton -query -current $button`)) {
- $currentLayer = $button;
- break;
- }
- }
-
- return $currentLayer;
- }
-
- proc removeAllLayerButtons()
- //
- // Description:
- // Remove all the layer buttons in the Layer Editor.
- //
- // This method needs to be (and should only be) called when a scene is
- // opened or a new scene is created.
- //
- {
- global string $gCurrentLayerEditor;
-
- if ("" == $gCurrentLayerEditor) {
- error ("There is no current Layer Editor");
- return;
- }
-
- setParent $gCurrentLayerEditor;
-
- string $button, $buttonArray[], $buttonLayout;
-
- // Delete all the display layer buttons.
- //
- $buttonLayout = "LayerEditorDisplayLayerLayout";
- $buttonArray = `layout -query -childArray $buttonLayout`;
- for ($button in $buttonArray) {
- deleteUI $button;
- }
-
- // Delete all the render layer buttons.
- //
- $buttonLayout = "LayerEditorRenderLayerLayout";
- $buttonArray = `layout -query -childArray $buttonLayout`;
- for ($button in $buttonArray) {
- deleteUI $button;
- }
- }
-
- global proc string[] sortLayers(string $layerArray[])
- //
- // Description:
- // Sort the layers in the argument array according to their
- // display order attribute.
- //
- // Arguments:
- // $layerArray[] - A string array of layer names.
- //
- // Returns:
- // A string array containing the sorted list of layers.
- //
- {
- string $result[];
- int $count, $index, $position, $positionArray[];
-
- // Construct an array consisting of each layer's display order
- // attribute value.
- //
- $count = size($layerArray);
- for ($index = 0; $index < $count; $index++) {
- $position = `getAttr ($layerArray[$index] + ".displayOrder")`;
- $positionArray[$index] = $position;
- }
-
- // Now sort the display order array.
- //
- $positionArray = sort($positionArray);
-
- // Construct the result array by matching the layer with it's
- // corresponding display order value.
- //
- for ($index = 0; $index < $count; $index++) {
- for ($layerIndex = 0; $layerIndex < $count; $layerIndex++) {
- if ("" != $layerArray[$layerIndex]) {
- $position = `getAttr ($layerArray[$layerIndex] + ".displayOrder")`;
- if ($positionArray[$index] == $position) {
- $result[$index] = $layerArray[$layerIndex];
- $layerArray[$layerIndex] = "";
- break;
- }
- }
- }
- }
-
- return $result;
- }
-
- global proc layerEditorNewScene()
- //
- // Description:
- // This procedure is called whenever the user creates a new scene.
- //
- // Update the Layer Editor to reflect any layer changes.
- //
- {
- removeAllLayerButtons();
- updateLayerEditor();
- }
-
- global proc layerEditorOpenScene()
- //
- // Description:
- // This procedure is called whenever the user opens a new scene.
- //
- // Update the Layer Editor to reflect any layer changes.
- //
- {
- removeAllLayerButtons();
- updateLayerEditor();
- }
-
- global proc layerEditorDisplayLayerChange()
- //
- // Description:
- // This procedure is called whenever the user creates or deletes
- // a display layer.
- //
- // Update the Layer Editor to reflect the layer changes.
- //
- {
- updateLayersByType("Display");
- }
-
- global proc layerEditorRenderLayerChange()
- //
- // Description:
- // This procedure is called whenever the user creates or deletes
- // a render layer.
- //
- // Update the Layer Editor to reflect the layer changes.
- //
- {
- updateLayersByType("Render");
- }
-
- global proc layerEditorLayerButtonSelect(
- int $modifiers,
- string $layerButton)
- //
- // Description:
- // This procedure is called whenever the selects a layer in
- // the editor.
- //
- // Arguments:
- // $modifiers - The state of the mouse modifiers.
- //
- // $layerButton - The name of the layer selected.
- //
- {
- global string $gCurrentLayerEditor;
- global int $gLayerEditorLastButtonSelection;
-
- string $currentSelection[], $remove[], $orderArray[];
- string $item, $gridLayout;
- int $select, $count = 0, $index, $startIndex, $endIndex;
- int $selectionPosition;
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- // Set the parent to the current layer editor. We can now use short
- // names of our controls and be certain they reference the correct
- // control.
- //
- setParent $gCurrentLayerEditor;
-
- // Get the current layer selection.
- //
- $currentSelection = getLayerSelection($type);
-
- // Get the layout containing the layer buttons.
- //
- if ("Display" == $type) {
- $gridLayout = "LayerEditorDisplayLayerLayout";
- } else {
- $gridLayout = "LayerEditorRenderLayerLayout";
- }
-
- if (0 == $modifiers) {
- //
- // No modifiers. Select the button and deselect any currently
- // selected buttons. Also make the selected button the current
- // layer.
- //
- if ("Display" == $type) {
- if (`layerButton -exists $layerButton`) {
- if (`objExists $layerButton`) {
- if (catch(`editDisplayLayerGlobals -currentDisplayLayer $layerButton`)) {
- //
- // If there was an error then that means that the layer belongs
- // to a layer in a referenced scene. Don't select the layer.
- //
- return;
- }
- }
- layerButton -edit -select true -current true $layerButton;
- }
-
- } else if ("Render" == $type) {
- if (`renderLayerButton -exists $layerButton`) {
- if (`objExists $layerButton`) {
- if (catch(`editRenderLayerGlobals -currentRenderLayer $layerButton`)) {
- //
- // If there was an error then that means that the layer belongs
- // to a layer in a referenced scene. Don't select the layer.
- //
- return;
- }
- }
- renderLayerButton -edit -select true -current true $layerButton;
- }
- }
-
- // Get the order array of layer buttons in the layout.
- //
- $orderArray = `gridLayout -query -gridOrder $gridLayout`;
-
- // If the selected button is already selected then remove
- // it from the list of buttons to deselect.
- //
- $remove[0] = $layerButton;
- $currentSelection = AWRemoveStringsFromStringArray(
- $remove, $currentSelection);
-
- // Deselect previously selected buttons.
- //
- for ($item in $currentSelection) {
- if ("Display" == $type) {
- layerButton -edit -select false $item;
- } else if ("Render" == $type) {
- renderLayerButton -edit -select false $item;
- }
- }
-
- // Make sure the previous current layer (if any) is reset.
- //
- for ($item in $orderArray) {
- if ("(null)" == $item) continue;
- if ($item != $layerButton) {
-
- if ("Display" == $type) {
- if (`layerButton -query -current $item`) {
- layerButton -edit -current false $item;
- }
-
- } else if ("Render" == $type) {
- if (`renderLayerButton -query -current $item`) {
- renderLayerButton -edit -current false $item;
- }
- }
- }
- }
-
- // Determine and save the position of the selected button.
- // Need the position of this button for range selecting with
- // the Shift modifier.
- //
- for ($index = 0; $index < size($orderArray); $index++) {
- if ($layerButton == $orderArray[$index]) {
- $gLayerEditorLastButtonSelection = $index;
- break;
- }
- }
-
- } else if (1 == $modifiers) {
- //
- // Shift modifier. Select the range of buttons from the button
- // that was just pressed to the last button pressed.
- //
-
- // Determine the position of the selected button.
- //
- $orderArray = `gridLayout -query -gridOrder $gridLayout`;
- for ($index = 0; $index < size($orderArray); $index++) {
- if ($layerButton == $orderArray[$index]) {
- $selectionPosition = $index;
- break;
- }
- }
-
- $startIndex = $endIndex = 0;
-
- if ($selectionPosition <= $gLayerEditorLastButtonSelection) {
- $startIndex = $selectionPosition;
- $endIndex = $gLayerEditorLastButtonSelection;
-
- } else if ($selectionPosition > $gLayerEditorLastButtonSelection) {
- $startIndex = $gLayerEditorLastButtonSelection;
- $endIndex = $selectionPosition;
- }
-
- for ($index = 0; $index < size($orderArray); $index++) {
- if ("(null)" == $orderArray[$index]) continue;
- $select = false;
- if ($index >= $startIndex && $index <= $endIndex) $select = true;
- if ("Display" == $type) {
- layerButton -edit -select $select $orderArray[$index];
- } else if ("Render" == $type) {
- renderLayerButton -edit -select $select $orderArray[$index];
- }
- }
-
- } else if (4 == $modifiers) {
- //
- // Ctrl modifier. Toggle the selection of the button.
- //
- if ("Display" == $type) {
- $select = `layerButton -query -select $layerButton`;
- layerButton -edit -select (!$select) $layerButton;
- } else if ("Render" == $type) {
- $select = `renderLayerButton -query -select $layerButton`;
- renderLayerButton -edit -select (!$select) $layerButton;
- }
-
- // Is this layer also the current one? If it is then make the
- // default layer current and mark this layer as no longer being
- // current.
- //
- if ("Display" == $type) {
- if (`layerButton -exists $layerButton`) {
- if (`layerButton -query -current $layerButton`) {
- layerButton -edit -current false $layerButton;
- editDisplayLayerGlobals -currentDisplayLayer "defaultLayer";
- }
- }
-
- } else if ("Render" == $type) {
- if (`renderLayerButton -exists $layerButton`) {
- if (`renderLayerButton -query -current $layerButton`) {
- renderLayerButton -edit -current false $layerButton;
- editRenderLayerGlobals -currentRenderLayer "defaultRenderLayer";
- }
- }
- }
- }
- }
-
- global proc layerEditorQuickEditWindowSave(string $layerArray[])
- //
- // Description:
- // This procedure is called when the user presses the Save button
- // in the Layer Edit window.
- //
- // Take the edit window values and apply them to the layer(s).
- //
- // Arguments:
- // $layerArray - The layer(s) being edited.
- //
- {
- global string $gCurrentLayerEditor;
-
- if (!`window -exists LayerEditorQuickEditWindow`) return;
-
- string $name, $layer, $layerType, $newName;
- int $visible, $renderable, $colorIndex, $type;
- int $layerCount;
-
- // Determine the layer type.
- //
- $layer = $layerArray[0];
- $layerType = `objectType $layer`;
-
- $layerCount = size($layerArray);
-
- setParent LayerEditorQuickEditWindow;
-
- // Determine the layer name from the edit window.
- //
- $name = `textFieldGrp -query -text NameField`;
-
- // Get the layer attributes from the window according to the
- // layer type.
- //
- if ("displayLayer" == $layerType) {
- $visible = `checkBoxGrp -query -value1 VisibleCheckBox`;
- $type = `optionMenuGrp -query -select TypeOptionMenu`;
- $colorIndex = `palettePort -query -setCurCell ColorPalette`;
-
- } else if ("renderLayer" == $layerType) {
- $renderable = `checkBoxGrp -query -value1 RenderableCheckBox`;
- }
-
- if (1 == $layerCount) {
- //
- // Only one layer edited.
- //
- if ($name == $layer) {
- //
- // User has not changed name of object. Just apply the
- // attributes.
- //
- if ("displayLayer" == $layerType) {
- setAttr ($layer + ".visibility") $visible;
- setAttr ($layer + ".displayType") ($type - 1);
- setAttr ($layer + ".color") $colorIndex;
-
- } else if ("renderLayer" == $layerType) {
- setAttr ($layer + ".renderable") $renderable;
- }
-
- } else {
- //
- // User has changed the name value.
- //
- // Check for empty name or invalid name.
- //
- if ("" == $name || !isValidName($name)) {
- confirmDialog
- -title "Warning"
- -parent LayerEditorQuickEditWindow
- -button "OK"
- -defaultButton "OK"
- -cancelButton "OK"
- -message ("The name \"" + $name + "\" is invalid. Valid names "
- + "contain alphanumeric\ncharacters only. Whitespace "
- + "characters are not allowed.");
- return;
-
- } else {
- //
- // Name change. Must check if an object by that name already
- // exists.
- //
- if (`objExists $name`) {
- confirmDialog
- -title "Warning"
- -parent LayerEditorQuickEditWindow
- -button "OK"
- -defaultButton "OK"
- -cancelButton "OK"
- -message ("An object by the name \"" + $name
- + "\" already exists.\nEnter a different name.");
- return;
-
- } else {
- //
- // Apply the attribute values.
- //
- if ("displayLayer" == $layerType) {
- setAttr ($layer + ".visibility") $visible;
- setAttr ($layer + ".displayType") ($type - 1);
- setAttr ($layer + ".color") $colorIndex;
-
- } else if ("renderLayer" == $layerType) {
- setAttr ($layer + ".renderable") $renderable;
- }
-
- // Rename the layer object.
- //
- // The renaming of the corresponding layer button will
- // happen in the proc assigned with the button's
- // -rc/renameCommand flag.
- //
- rename $layer $name;
- }
- }
- }
-
- } else {
- //
- // More than one layer edited.
- //
- for ($layer in $layerArray) {
- if ("displayLayer" == $layerType) {
- setAttr ($layer + ".visibility") $visible;
- setAttr ($layer + ".displayType") ($type - 1);
- setAttr ($layer + ".color") $colorIndex;
-
- } else if ("renderLayer" == $layerType) {
- setAttr ($layer + ".renderable") $renderable;
- }
- }
- }
-
- deleteUI -window LayerEditorQuickEditWindow;
- }
-
- global proc createLayerEditorQuickEditWindow(string $layerArray[])
- //
- // Description:
- // Create a quick edit window for the user to modify the layer
- // attributes.
- //
- // Arguments:
- // $layerArray - The layer(s) to edit.
- //
- {
- string $window, $form, $body, $buttonForm;
- string $name, $nameField, $visibleCheckBox, $typeOptionMenu;
- string $colorLabel, $colorPalette, $saveButton, $cancelButton;
- string $renderableCheckBox, $layer, $layerType;
- string $windowTitle;
- int $visible, $displayType, $colorIndex, $renderable, $index;
- int $layerCount;
-
- // Make sure an argument has been supplied.
- //
- $layerCount = size($layerArray);
- if (1 > $layerCount) {
- error ("Must supply a layer argument");
- return;
- }
-
- $layer = $layerArray[0];
-
- // Get the layer type.
- //
- $layerType = `objectType $layer`;
-
- // Delete the window if it already exists.
- //
- if (`window -exists LayerEditorQuickEditWindow`) {
- deleteUI -window LayerEditorQuickEditWindow;
- }
-
- // Create the window and the top level layout.
- //
- if (1 < $layerCount) $windowTitle = "Edit Layers";
- else $windowTitle = "Edit Layer";
- $window = `window -title $windowTitle -iconName $windowTitle LayerEditorQuickEditWindow`;
- $form = `formLayout`;
-
- // Activate the default UI template for consistent alignment.
- //
- setUITemplate -pushTemplate OptionsTemplate;
-
- // Get the name of the first layer. If we are editing more than one
- // layer then construct a string that contains all the layer names.
- // It should look something like:
- //
- // layer1, layer2, layer3...
- //
- // Append ellispes if there are too many layers.
- //
- int $kNameDisplayLimit = 3;
- $name = $layer;
- if (1 < $layerCount) {
- for ($index = 1; ($index < $layerCount && $index < $kNameDisplayLimit); $index++) {
- $name += ", ";
- $name += $layerArray[$index];
- }
- if ($layerCount > $kNameDisplayLimit) {
- $name += "...";
- }
- }
-
- if ("displayLayer" == $layerType) {
- $visible = `getAttr ($layer + ".visibility")`;
- $displayType = `getAttr ($layer + ".displayType")`;
- $colorIndex = `getAttr ($layer + ".color")`;
-
- } else if ("renderLayer" == $layerType) {
- $renderable = `getAttr ($layer + ".renderable")`;
- }
-
- // ----------------------------------------------------------------------
- //
- // Body.
- //
- setParent $form;
- $body = `columnLayout -rowSpacing 4`;
-
- $nameField = `textFieldGrp -label "Name" -text $name
- -editable (1 == $layerCount) NameField`;
-
- if ("displayLayer" == $layerType) {
- $typeOptionMenu = `optionMenuGrp -label "Display Type" TypeOptionMenu`;
- menuItem -label "Normal";
- menuItem -label "Template";
- menuItem -label "Reference";
- optionMenuGrp -edit -select ($displayType + 1) $typeOptionMenu;
-
- $visibleCheckBox = `checkBoxGrp -numberOfCheckBoxes 1
- -label "" -label1 "Visible"
- -value1 $visible
- VisibleCheckBox`;
-
- rowLayout -numberOfColumns 2 -columnAttach 2 "left" 0;
-
- $colorLabel = `text -label "Color" -align "right"`;
- frameLayout -labelVisible false -borderStyle "in"
- -collapsable false -collapse false;
-
- int $cellHeight = 17, $cellWidth = 17;
- int $rows = 2, $columns = 16;
-
- $colorPalette = `palettePort
- -dimensions $columns $rows
- -width ($columns * $cellWidth)
- -height ($rows * $cellHeight)
- -transparent 0
- -topDown true
- -colorEditable false
- -setCurCell $colorIndex
- ColorPalette`;
-
- // Fill in the colour palette with the color's mapped to the
- // colour indecies.
- //
- float $colorComponentArray[];
- for ($index = 1; $index <= 31; $index++) {
- $colorComponentArray = `colorIndex -query $index`;
- palettePort -edit -rgbValue $index
- $colorComponentArray[0]
- $colorComponentArray[1]
- $colorComponentArray[2]
- $colorPalette;
- }
-
- // Set the colour of the "transparent" cell to be a light grey.
- // Note that the "transparent" cell really indicates "no colour
- // assignment".
- //
- palettePort -edit -rgbValue 0 0.60 0.60 0.60 $colorPalette;
-
- } else if ("renderLayer" == $layerType) {
- $renderableCheckBox = `checkBoxGrp -numberOfCheckBoxes 1
- -label "" -label1 "Renderable"
- -value1 $renderable
- RenderableCheckBox`;
- }
-
- // ----------------------------------------------------------------------
- //
- // Buttons.
- //
- setParent $form;
- $buttonForm = `formLayout -parent $form`;
-
- // Save button.
- //
- string $saveCommandStr = "layerEditorQuickEditWindowSave { ";
- for ($index = 0; $index < $layerCount; $index++) {
- $saveCommandStr += ("\"" + $layerArray[$index] + "\"");
- if ($index < ($layerCount - 1)) {
- $saveCommandStr += ", ";
- }
- }
- $saveCommandStr += " }";
-
- $saveButton = `button -label "Save" -command ($saveCommandStr)`;
-
- // Cancel button.
- //
- $cancelButton = `button -label "Cancel"
- -command ("deleteUI -window " + $window)`;
-
- formLayout -edit
- -attachForm $saveButton "top" 0
- -attachForm $saveButton "left" 0
- -attachForm $saveButton "bottom" 0
- -attachPosition $saveButton "right" 2 50
-
- -attachForm $cancelButton "top" 0
- -attachPosition $cancelButton "left" 2 50
- -attachForm $cancelButton "bottom" 0
- -attachForm $cancelButton "right" 0
- $buttonForm;
-
- formLayout -edit
- -attachForm $body "top" 4
- -attachForm $body "left" 4
- -attachControl $body "bottom" 4 $buttonForm
- -attachForm $body "right" 4
-
- -attachNone $buttonForm "top"
- -attachForm $buttonForm "left" 4
- -attachForm $buttonForm "bottom" 4
- -attachForm $buttonForm "right" 4
- $form;
-
- // Deactivate the default UI template.
- //
- setUITemplate -popTemplate;
-
- showWindow $window;
- }
-
- global proc layerEditorLayerButtonRename(
- string $oldName,
- string $newName)
- //
- // Description:
- // This procedure is called whenever a layer node is renamed.
- // It is necessary to also rename the corresponding layer button.
- //
- // Arguments:
- // oldName - The old layer name.
- //
- // newName - The new layer name.
- //
- {
- global string $gCurrentLayerEditor;
-
- setParent $gCurrentLayerEditor;
-
- renameUI $oldName $newName;
- }
-
- global proc layerEditorLayerButtonVisibilityChange(string $layer)
- //
- // Description:
- // This procedure is called whenever the user presses the visibility
- // indicator in a display layer button.
- //
- // Toggle the visibility of the layer.
- //
- // Arguments:
- // $layer - The layer.
- //
- {
- int $visible = `getAttr ($layer + ".visibility")`;
-
- if (0 == $visible) $visible = true;
- else $visible = false;
-
- setAttr ($layer + ".visibility") $visible;
- }
-
- global proc layerEditorLayerButtonTypeChange(string $layer)
- //
- // Description:
- // This procedure is called whenever the user presses the type
- // indicator in a display layer button.
- //
- // Cycle the type of the layer.
- //
- // Current layer types are: Normal, Reference, and Template.
- //
- // Arguments:
- // $layer - The layer.
- //
- {
- int $type = `getAttr ($layer + ".displayType")`;
-
- if (0 == $type) $type = 1;
- else if (1 == $type) $type = 2;
- else $type = 0;
-
- setAttr ($layer + ".displayType") $type;
- }
-
- global proc layerEditorLayerButtonRenderabilityChange(string $layer)
- //
- // Description:
- // This procedure is called whenever the user presses the renderable
- // indicator in a render layer button.
- //
- // Toggle the renderability of the layer.
- //
- // Arguments:
- // $layer - The layer.
- //
- {
- int $renderable = `getAttr ($layer + ".renderable")`;
-
- if (0 == $renderable) $renderable = true;
- else $renderable = false;
-
- setAttr ($layer + ".renderable") $renderable;
- }
-
- global proc string [] layerEditorLayerButtonDrag(
- string $dragControl,
- int $x,
- int $y,
- int $mods)
- //
- // Description:
- // This procedure is called whenever the user begins a drag from
- // a layer button.
- //
- // Set up a drag message so we can detect it on the drop callback.
- //
- // Arguments:
- // $dragControl - The layer button where the drag occurred.
- //
- // $x, $y - Location of the drag event.
- //
- // $mods - State of the mouse modifiers.
- //
- // Returns:
- // A string array value representing the type of drag message.
- //
- {
- string $result[] = {"LayerButtonDragMessage"};
- return $result;
- }
-
- global proc layerEditorLayerButtonDrop(
- string $dragControl,
- string $dropControl,
- string $messages[],
- int $x,
- int $y,
- int $dragType)
- //
- // Description:
- // This procedure is called whenever the user ends a drag from
- // a layer button to another layer button.
- //
- // If the drag message is the correct type then reorder the
- // layer buttons.
- //
- // Arguments:
- // $dragControl - The layer button where the drag occurred.
- //
- // $dropControl - The layer button where the drop occurred.
- //
- // $messages[] - The drag messages corresponding to the event.
- //
- // $x, $y - Location of the drag event.
- //
- // $dragType - Type of drag event.
- //
- {
- global string $gCurrentLayerEditor;
-
- string $type, $gridLayout = "", $orderArray[];
- string $tokenArray[], $shortName = "";
- int $index, $tokenCount, $dragPosition = 0, $dropPosition = 0;
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- // Set the parent to the current layer editor. We can now use short
- // names of our controls and be certain they reference the correct
- // control.
- //
- setParent $gCurrentLayerEditor;
-
- if ("Display" == $type) {
- $gridLayout = "LayerEditorDisplayLayerLayout";
-
- } else if ("Render" == $type) {
- $gridLayout = "LayerEditorRenderLayerLayout";
- }
-
- if ("LayerButtonDragMessage" == $messages[0]) {
-
- // Note that the drag and drop control arguments are long names and
- // the items in the grid's array are short names (long names
- // contain the full path).
- //
- $dropControl = getShortName($dropControl);
- $dragControl = getShortName($dragControl);
-
- $orderArray = `gridLayout -query -gridOrder $gridLayout`;
-
- // Determine the drag and drop positions.
- //
- for ($index = 0; $index < size($orderArray); $index++) {
- if ($dragControl == $orderArray[$index]) {
- $dragPosition = $index + 1;
- }
- if ($dropControl == $orderArray[$index]) {
- $dropPosition = $index + 1;
- }
- }
-
- if ($dragPosition < $dropPosition) {
-
- // Put drag control at drop position.
- //
- gridLayout -edit -position $dragControl $dropPosition $gridLayout;
-
- // Shuffle the items following the drop position.
- //
- for ($index = $dragPosition + 1; $index <= $dropPosition; $index++) {
- gridLayout -edit -position $orderArray[$index - 1] ($index - 1) $gridLayout;
- }
-
- } else if ($dragPosition > $dropPosition) {
-
- // Put drag control at drop position.
- //
- gridLayout -edit -position $dragControl $dropPosition $gridLayout;
-
- // Shuffle the items following the drop position.
- //
- for ($index = $dragPosition - 1; $index >= $dropPosition; $index--) {
- gridLayout -edit -position $orderArray[$index - 1] ($index + 1) $gridLayout;
- }
-
- } else {
- //
- // Drag position is same as drop position. Nothing to do.
- //
- }
- }
-
- updateLayerOrderByType($type);
- }
-
- global proc layerEditorShowEditMenu(string $menu)
- //
- // Description:
- // This procedure is called whenever the user shows the Edit menu.
- //
- // Update the enable state of the menu items to reflect the possible
- // options.
- //
- // Arguments:
- // $menu - The menu.
- //
- {
- string $selection[] = `ls -selection`;
- string $layerSelection[] = getLayerSelection("");
- string $layerContents[], $remove[];
- string $currentLayer = getCurrentLayer("");
- string $type;
- int $enable = false;
-
- $type = getLayerDisplayType();
-
- // Remove layers from the selection list.
- //
- $remove = `ls -type displayLayer`;
- $selection = AWRemoveStringsFromStringArray($remove, $selection);
- $remove = `ls -type renderLayer`;
- $selection = AWRemoveStringsFromStringArray($remove, $selection);
-
- setParent -menu $menu;
-
- // Delete layer. Enable if there is at least one layer selected.
- //
- $enable = false;
- if (0 < size($layerSelection)) $enable = true;
- menuItem -edit -enable $enable LayerEditorEditMenuDeleteMenuItem;
-
- // Edit layer. Enable if there is a current layer.
- //
- $enable = false;
- if ("" != $currentLayer) $enable = true;
- menuItem -edit -enable $enable LayerEditorEditMenuEditMenuItem;
-
- // Select objects in selected layer(s). Enable if there is at least
- // one layer selected and there is at least one object in any of
- // those layers.
- //
- $enable = false;
- for ($layer in $layerSelection) {
- if ("Display" == $type) {
- $layerContents = `editDisplayLayerMembers -query $layer`;
- } else if ("Render" == $type) {
- $layerContents = `editRenderLayerMembers -query $layer`;
- }
- if (0 < size($layerContents)) {
- $enable = true;
- break;
- }
- }
- menuItem -edit -enable $enable LayerEditorEditMenuSelectObjectsMenuItem;
-
- // Add selected objects to current layer. Enable if there is a
- // current layer and objects on the selection list.
- //
- $enable = false;
- if ("" != $currentLayer && 0 < size($selection)) $enable = true;
- menuItem -edit -enable $enable LayerEditorEditMenuAddObjectsMenuItem;
-
- // Remove objects from selected layer(s). Enable if there is at least
- // one layer selected and there is at least one object in any of
- // those layers.
- //
- $enable = false;
- for ($layer in $layerSelection) {
- if ("Display" == $type) {
- $layerContents = `editDisplayLayerMembers -query $layer`;
- } else if ("Render" == $type) {
- $layerContents = `editRenderLayerMembers -query $layer`;
- }
- if (0 < size($layerContents)) {
- $enable = true;
- break;
- }
- }
- menuItem -edit -enable $enable LayerEditorEditMenuRemoveObjectsMenuItem;
-
- // Remove selected objects from whatever layer they might be in. In other
- // words add the selected objects to the default layer.
- //
- // Enable this item if there are selected objects.
- //
- $enable = false;
- if (0 < size($selection)) $enable = true;
- menuItem -edit -enable $enable LayerEditorEditMenuRemoveFromLayerMenuItem;
-
- // Show Layer Attributes. Enable if there is a current layer.
- //
- $enable = false;
- if ("" != $currentLayer) $enable = true;
- menuItem -edit -enable $enable LayerEditorEditMenuLayerAttributesMenuItem;
- }
-
- global proc layerEditorShowOptionsMenu(string $menu)
- //
- // Description:
- // This procedure is called whenever the user shows the Options menu.
- //
- // Update the state of the menu items.
- //
- // Arguments:
- // $menu - The menu.
- //
- {
- setParent -menu $menu;
-
- $value = `optionVar -query displayLayerCurrent`;
- menuItem -edit -checkBox $value LayerEditorOptionsMenuMakeCurrentMenuItem;
-
- $value = `editDisplayLayerGlobals -query -useCurrent`;
- menuItem -edit -checkBox $value LayerEditorOptionsMenuUseCurrentMenuItem;
- }
-
- global proc layerEditorShowPopupMenu(string $menu, string $layerButton)
- //
- // Description:
- // This procedure is called when the popup menu on layer buttons
- // is shown.
- //
- // Create the menu items.
- //
- // Arguments:
- // $menu - The parent menu.
- //
- // $layer - The full path name to the layer button.
- //
- {
- string $selection[] = `ls -selection`;
- string $layerContents[], $type, $layer;
- int $enable = false;
-
- // Get the current layer type.
- //
- $type = getLayerDisplayType();
-
- // Get the short name of the layer from the layer button argument.
- //
- $layer = getShortName($layerButton);
-
- // Get the contents of this layer.
- //
- if ("Display" == $type) {
- $layerContents = `editDisplayLayerMembers -query $layer`;
- } else if ("Render" == $type) {
- $layerContents = `editRenderLayerMembers -query $layer`;
- }
-
- // Remove layers from the selection list.
- //
- $remove = `ls -type displayLayer`;
- $selection = AWRemoveStringsFromStringArray($remove, $selection);
- $remove = `ls -type renderLayer`;
- $selection = AWRemoveStringsFromStringArray($remove, $selection);
-
- // Set the menu parent and delete all the items in the menu.
- //
- setParent -menu $menu;
- menu -edit -deleteAllItems $menu;
-
- //
- // Now create the menu items...
- //
-
- // New layer.
- //
- menuItem -label "Create Layer" -command ("layerEditorCreateLayer");
-
- // Delete this layer only (as opposed to deleting all the selected layers).
- //
- menuItem -label "Delete"
- -command ("evalDeferred (\"layerEditorDeleteLayer " + $layer + "\")");
-
- // Edit layer.
- //
- menuItem -label "Edit Layer..." -command ("layerEditorEditLayer " + $layer);
-
- menuItem -divider true;
-
- // Select objects in this layer. Enable if this layer contains
- // an object.
- //
- $enable = false;
- if (0 < size($layerContents)) $enable = true;
- menuItem -label "Select Objects" -enable $enable
- -command ("layerEditorSelectObjects " + $layer);
-
- // Add selected objects to this layer. Enable if there is at least
- // one object on the selection list.
- //
- $enable = false;
- if (0 < size($selection)) $enable = true;
- menuItem -label "Add Selected Objects" -enable $enable
- -command ("layerEditorAddObjects " + $layer);
-
- // Remove objects from this layer. Enable if this layer contains
- // an object.
- //
- $enable = false;
- if (0 < size($layerContents)) $enable = true;
- menuItem -label "Remove Objects" -enable $enable
- -command ("layerEditorRemoveObjects " + $layer);
-
- menuItem -divider true;
-
- menuItem -label "Attributes..."
- -command ("layerEditorLayerAttributes " + $layer);
- menuItem -label "Membership..."
- -command ("layerEditorMembership " + $layer);
- }
-
- global proc layerEditorCreateLayer()
- //
- // Description:
- // Create a new layer of the appropriate type and update the
- // editor to reflect the change.
- //
- {
- global string $gCurrentLayerEditor;
-
- string $type, $createLayerCmd = "";
- string $newLayer, $layer, $currentSelection[];
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- // Set the parent to the current layer editor. We can now use short
- // names of our controls and be certain they reference the correct
- // control.
- //
- setParent $gCurrentLayerEditor;
-
- if ("Display" == $type) {
- $createLayerCmd = "performCreateDisplayLayer 0";
-
- } else if ("Render" == $type) {
- $createLayerCmd = "performCreateRenderLayer 0";
- }
-
- if ("" != $createLayerCmd) {
- eval ($createLayerCmd);
- }
-
- updateLayersByType($type);
-
- // Select and make current the new layer if the option to do so is set.
- //
- if (`optionVar -query displayLayerCurrent`) {
-
- // Deselect any selected layers.
- //
- $currentSelection = getLayerSelection($type);
- for ($layer in $currentSelection) {
- if ("Display" == $type) {
- layerButton -edit -select false -current false $layer;
- } else if ("Render" == $type) {
- renderLayerButton -edit -select false -current false $layer;
- }
- }
-
- // Select and make current the new layer.
- //
- if ("Display" == $type) {
- $newLayer = `editDisplayLayerGlobals -query -currentDisplayLayer`;
- if (`layerButton -exists $newLayer`) {
- layerButton -edit -select true -current true $newLayer;
- }
- } else if ("Render" == $type) {
- $newLayer = `editRenderLayerGlobals -query -currentRenderLayer`;
- if (`renderLayerButton -exists $newLayer`) {
- renderLayerButton -edit -select true -current true $newLayer;
- }
- }
- }
- }
-
- global proc layerEditorDeleteLayer(string $layer)
- //
- // Description:
- // Delete the specified layer or if no layer argument given then
- // delete all the current selected layers.
- //
- // Arguments:
- // $layer - The specific layer to delete, or an empty string to
- // delete all selected layers.
- //
- {
- string $type, $item, $currentSelection[];
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- if ("" != $layer) {
- //
- // Delete the specified layer.
- //
- deleteUI -control $layer;
-
- // Delete the layer object.
- //
- delete $layer;
-
- } else {
- //
- // Delete the selected layers.
- //
-
- // Get the selected layers.
- //
- $currentSelection = getLayerSelection("");
-
- // Delete all the selected layers.
- //
- for ($item in $currentSelection) {
-
- // Delete the layer button.
- //
- deleteUI -control $item;
-
- // Delete the layer object.
- //
- delete $item;
- }
- }
-
- updateLayersByType($type);
- }
-
- global proc layerEditorEditLayer(string $layer)
- //
- // Description:
- // Edit the specified layer or if no layer argument given then
- // edit the selected layers.
- //
- // Arguments:
- // $layer - The specific layer to edit, or an empty string to
- // edit the selected layers.
- //
- {
- string $layerArray[];
-
- // Get the layer selection if the argument is an empty string.
- //
- if ("" == $layer) {
- $layerArray = getLayerSelection("");
-
- } else {
- $layerArray[0] = $layer;
- }
-
- // Show the layer edit window.
- //
- createLayerEditorQuickEditWindow($layerArray);
- }
-
- global proc layerEditorSelectObjects(string $layer)
- //
- // Description:
- // Select the objects contained in the specified layer or if no
- // layer argument given then select all the objects in the selected
- // layers.
- //
- // Arguments:
- // $layer - The specific layer to select the objects from, or an empty
- // string to select all the objects from all selected layers.
- //
- {
- string $type, $item, $currentSelection[];
-
- // Clear the current object selection list.
- //
- select -clear;
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- if ("" != $layer) {
- //
- // Select the objects in the given layer.
- //
- if ("Display" == $type) {
- select -add `editDisplayLayerMembers -fullNames -query $layer`;
- } else if ("Render" == $type) {
- select -add `editRenderLayerMembers -fullNames -query $layer`;
- }
-
- } else {
- //
- // Get the selected layers.
- //
- $currentSelection = getLayerSelection($type);
-
- // Add to the selection list the objects contained in each
- // selected layer.
- //
- for ($item in $currentSelection) {
- if ("Display" == $type) {
- select -add `editDisplayLayerMembers -fullNames -query $item`;
- } else if ("Render" == $type) {
- select -add `editRenderLayerMembers -fullNames -query $item`;
- }
- }
- }
- }
-
- global proc layerEditorAddObjects(string $layer)
- //
- // Description:
- // Add the objects on the selection list to the specified layer or if
- // no layer argument given then add the objects to the current layer.
- //
- // Arguments:
- // $layer - The specific layer to add the objects to, or an empty
- // string to add the objects to the current layer.
- //
- {
- // Get the current layer if the argument is an empty string.
- //
- if ("" == $layer) $layer = getCurrentLayer("");
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- // Add the objects to the layer.
- //
- if ("" != $layer) {
- if (`optionVar -query displayLayerContents` == 2) {
- if ("Display" == $type) {
- editDisplayLayerMembers -noRecurse $layer `ls -selection`;
- } else if ("Render" == $type) {
- editRenderLayerMembers -noRecurse $layer `ls -selection`;
- }
-
- } else {
- if ("Display" == $type) {
- editDisplayLayerMembers $layer `ls -selection`;
- } else if ("Render" == $type) {
- editRenderLayerMembers $layer `ls -selection`;
- }
- }
- }
- }
-
- global proc layerEditorRemoveObjects(string $layer)
- //
- // Description:
- // Remove all the objects contained in the specified layer or if no
- // layer argument given then remove all the objects in the selected
- // layers.
- //
- // Arguments:
- // $layer - The specific layer to remove the objects from, or an empty
- // string to remove all the objects from all selected layers.
- //
- {
- string $type, $item, $currentSelection[];
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- if ("" != $layer) {
- //
- // Add to the default layer all the objects in the given layer.
- //
- if ("Display" == $type) {
- editDisplayLayerMembers "defaultLayer"
- `editDisplayLayerMembers -fullNames -query $layer`;
- } else if ("Render" == $type) {
- editRenderLayerMembers "defaultRenderLayer"
- `editRenderLayerMembers -fullNames -query $layer`;
- }
-
- } else {
- //
- // Get the selected layers.
- //
- $currentSelection = getLayerSelection($type);
-
- // Add to the default layer all the objects in the selected
- // layer(s).
- //
- for ($item in $currentSelection) {
- if ("Display" == $type) {
- editDisplayLayerMembers "defaultLayer"
- `editDisplayLayerMembers -fullNames -query $item`;
- } else if ("Render" == $type) {
- editRenderLayerMembers "defaultRenderLayer"
- `editRenderLayerMembers -fullNames -query $item`;
- }
- }
- }
- }
-
- global proc layerEditorSelectUnused()
- //
- // Description:
- // Select all the layers that don't have any objects in them.
- //
- {
- global string $gCurrentLayerEditor;
-
- string $type, $objectType, $layer, $layout;
- string $layerArray[], $layerContents[];
- string $selectArray[], $currentSelection[];
- int $index;
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- // Set the parent to the current layer editor. We can now use short
- // names of our controls and be certain they reference the correct
- // control.
- //
- setParent $gCurrentLayerEditor;
-
- // Get the current layer selection.
- //
- $currentSelection = getLayerSelection($type);
-
- // Determine the object type of layers being displayed.
- //
- if ("Display" == $type) {
- $objectType = "displayLayer";
- } else {
- $objectType = "renderLayer";
- }
-
- // Get all layers of the appropriate type.
- //
- $layerArray = `ls -type $objectType`;
-
- // Determine the contents of each layer. Ignore default layers.
- //
- $index = 0;
- for ($layer in $layerArray) {
-
- // Ignore default layers. Default layers have an id of 0.
- //
- if (0 < `getAttr ($layer + ".identification")`) {
- if ("Display" == $type) {
- $layerContents = `editDisplayLayerMembers -query $layer`;
- } else if ("Render" == $type) {
- $layerContents = `editRenderLayerMembers -query $layer`;
- }
- if (0 == size($layerContents)) {
- //
- // This layer has nothing in it. Add it to array.
- //
- $selectArray[$index++] = $layer;
- }
- }
- }
-
- //
- // Deselect any selected layers.
- //
- for ($layer in $currentSelection) {
- if ("Display" == $type) {
- layerButton -edit -select false -current false $layer;
- } else if ("Render" == $type) {
- renderLayerButton -edit -select false -current false $layer;
- }
- }
-
- // Select all the unused layers.
- //
- for ($layer in $selectArray) {
- if ("Display" == $type) {
- layerButton -edit -select true $layer;
- } else if ("Render" == $type) {
- renderLayerButton -edit -select true $layer;
- }
- }
- }
-
- global proc layerEditorRemoveFromLayer()
- //
- // Description:
- // Remove the selected objects from whatever layer they might be in.
- //
- {
- string $type, $object, $selection[], $remove[];
-
- $type = getLayerDisplayType();
-
- // Get the selection list.
- //
- $selection = `ls -selection`;
-
- // Remove layers from the selection list.
- //
- $remove = `ls -type displayLayer`;
- $selection = AWRemoveStringsFromStringArray($remove, $selection);
- $remove = `ls -type renderLayer`;
- $selection = AWRemoveStringsFromStringArray($remove, $selection);
-
- for ($object in $selection) {
- if ("Display" == $type) {
- editDisplayLayerMembers "defaultLayer" $object;
- } else if ("Render" == $type) {
- editRenderLayerMembers "defaultRenderLayer" $object;
- }
- }
- }
-
- global proc layerEditorLayerAttributes(string $layer)
- //
- // Description:
- // Show the Attribute Editor for the specified layer or if
- // no layer argument given then use the current layer.
- //
- // Arguments:
- // $layer - The specific layer to show the Attribute Editor for,
- // or an empty string to show the editor for the current layer.
- //
- {
- // Get the current layer if the argument is an empty string.
- //
- if ("" == $layer) $layer = getCurrentLayer("");
-
- // Get the current layer.
- //
- if ("" != $layer) {
-
- // Actually select the layer object.
- //
- select -replace $layer;
-
- // Show the Attribute Editor.
- //
- editSelected();
- }
- }
-
- global proc layerEditorMembership(string $layer)
- //
- // Description:
- // Show the Relationship Editor for the specified layer or if
- // no layer argument given then use the layer selection.
- //
- // Arguments:
- // $layer - The specific layer to show the Relationship Editor for,
- // or an empty string to show the editor for the selected
- // layers.
- //
- {
- string $selection[];
-
- if ("" != $layer) {
- $selection[0] = $layer;
-
- } else {
- //
- // Get the current selection.
- //
- $selection = getLayerSelection("");
- }
-
- // Show the Relationship Editor.
- //
- relationshipEditor("displayLayers", 7, $selection, {});
- }
-
- global proc layerEditorDisplayTypeChange()
- //
- // Description:
- // This procedure is called whenever the user changes the type
- // of layers displayed in the Layer Editor.
- //
- {
- global string $gCurrentLayerEditor;
-
- string $type, $tab = "";
-
- // Get the type of layers currently displayed in the editor.
- //
- $type = getLayerDisplayType();
-
- if ("Display" == $type) {
- $tab = "DisplayLayerTab";
- } else if ("Render" == $type) {
- $tab = "RenderLayerTab";
- }
-
- setParent $gCurrentLayerEditor;
-
- if ("" != $tab) {
- tabLayout -edit -selectTab $tab DisplayLayerUITabLayout;
- }
- }
-
- global proc updateLayersByType(string $type)
- //
- // Description:
- // Update the Layer Editor according to the specified type.
- //
- // Create and/or delete layer buttons as necessary.
- //
- // Arguments:
- // $type - Type of layers to update. Values are "Display" or
- // "Render".
- //
- {
- global string $gCurrentLayerEditor;
-
- if ("" == $gCurrentLayerEditor) {
- error ("There is no current Layer Editor");
- return;
- }
-
- setParent $gCurrentLayerEditor;
-
- string $buttonLayout, $objectType;
- string $layer, $layerArray[];
- string $button, $buttonArray[];
- string $removeArray[];
- int $layerID, $index, $colorIndex, $transparent;
-
- // Width of layer buttons.
- //
- int $kLayerButtonWidth = 350;
-
- if ("Display" == $type) {
- $buttonLayout = "LayerEditorDisplayLayerLayout";
- $objectType = "displayLayer";
-
- } else if ("Render" == $type) {
- $buttonLayout = "LayerEditorRenderLayerLayout";
- $objectType = "renderLayer";
-
- } else {
- error ("Invalid layer type: " + $type);
- return;
- }
-
- // Get all layers of the appropriate type.
- //
- $layerArray = `ls -type $objectType`;
-
- // Remove the default layers. Default layers have an id of 0.
- //
- $index = 0;
- for ($layer in $layerArray) {
- if (0 == `getAttr ($layer + ".identification")`) {
- $removeArray[$index++] = $layer;
- }
- }
- $layerArray = AWRemoveStringsFromStringArray($removeArray, $layerArray);
-
- // Now sort the remaining layers according to their display order.
- //
- $layerArray = sortLayers($layerArray);
-
- // Get the current array of layer buttons.
- //
- $buttonArray = `layout -query -childArray $buttonLayout`;
-
- // Add buttons for new layers.
- //
- for ($layer in $layerArray) {
- if (0 == AWNumberOfOccurrencesInStringArray($layer, $buttonArray)) {
- //
- // Create button.
- //
- if ("Display" == $type) {
- $transparent = false;
- $colorIndex = `getAttr ($layer + ".color")`;
- if (0 == $colorIndex) $transparent = true;
-
- layerButton -parent $buttonLayout
- -label $layer
- -name $layer
- -transparent $transparent
- -width $kLayerButtonWidth
- -command ("layerEditorLayerButtonSelect #m #1")
- -doubleClickCommand ("createLayerEditorQuickEditWindow { \"#1\" }")
- -renameCommand ("layerEditorLayerButtonRename #1 #2")
- -typeCommand ("layerEditorLayerButtonTypeChange #1")
- -visibleCommand ("layerEditorLayerButtonVisibilityChange #1")
- -dropCallback ("layerEditorLayerButtonDrop")
- -dragCallback ("layerEditorLayerButtonDrag")
- $layer;
-
- } else if ("Render" == $type) {
- renderLayerButton -parent $buttonLayout
- -label $layer
- -name $layer
- -width $kLayerButtonWidth
- -command ("layerEditorLayerButtonSelect #m #1")
- -doubleClickCommand ("createLayerEditorQuickEditWindow { \"#1\" }")
- -renameCommand ("layerEditorLayerButtonRename #1 #2")
- -renderableCommand ("layerEditorLayerButtonRenderabilityChange #1")
- -dropCallback ("layerEditorLayerButtonDrop")
- -dragCallback ("layerEditorLayerButtonDrag")
- $layer;
- }
-
- // Attach a popup menu to each layer button.
- //
- $popupMenu = `popupMenu -button 3 -parent $layer`;
- popupMenu -edit
- -postMenuCommand ("layerEditorShowPopupMenu #1 #2")
- $popupMenu;
-
- }
- }
-
- // Remove buttons for deleted layers.
- //
- $buttonArray = `layout -query -childArray $buttonLayout`;
- for ($button in $buttonArray) {
- if (!`objExists $button`) {
- //
- // Delete button.
- //
- deleteUI $button;
- }
- }
-
- if (0 < size($buttonArray) || 0 < size($layerArray)) {
- updateLayerOrderByType($type);
- }
- }
-
- global proc updateLayerOrderByType(string $type)
- //
- // Description:
- // Update the order of layers given their current display order.
- //
- // Set the layer's display order attribute based on the layer
- // button's position in the editor.
- //
- // Arguments:
- // $type - Type of layer. Values are "Display" or "Render".
- //
- {
- global string $gCurrentLayerEditor;
-
- if ("" == $gCurrentLayerEditor) {
- error ("There is no current Layer Editor");
- return;
- }
-
- setParent $gCurrentLayerEditor;
-
- string $buttonLayout, $objectType;
- string $layer, $layerArray[];
- string $button, $buttonArray[];
- string $removeArray[];
- int $index;
-
- if ("Display" == $type) {
- $buttonLayout = "LayerEditorDisplayLayerLayout";
- $objectType = "displayLayer";
-
- } else if ("Render" == $type) {
- $buttonLayout = "LayerEditorRenderLayerLayout";
- $objectType = "renderLayer";
-
- } else {
- error ("Invalid layer type: " + $type);
- return;
- }
-
- // Get all the layers of the appropriate type.
- //
- $layerArray = `ls -type $objectType`;
-
- // Remove the default layers. Default layers have an id of 0.
- //
- $index = 0;
- for ($layer in $layerArray) {
- if (0 == `getAttr ($layer + ".identification")`) {
- $removeArray[$index++] = $layer;
- }
- }
- $layerArray = AWRemoveStringsFromStringArray($removeArray, $layerArray);
-
- // Set the display order attribute for each layer.
- //
- $buttonArray = `gridLayout -query -gridOrder $buttonLayout`;
- for ($index = 0; $index < size($buttonArray); $index++) {
- if (`objExists $buttonArray[$index]`) {
- setAttr ($buttonArray[$index] + ".displayOrder") ($index + 1);
- }
- }
- }
-
- global proc updateLayerEditor()
- //
- // Description:
- // Update the Layer Editor.
- //
- // This procedure must be called whenever the state of layers in
- // the scene changes. For example, a new scene is created, or a
- // scene is opened, or a layer is added or removed.
- //
- {
- updateLayersByType("Display");
- updateLayersByType("Render");
- }
-
- global proc int layerEditorVisibilityStateChange(
- int $newState,
- string $layout)
- //
- // Description:
- // This procedure is called whenever the visibility state of the
- // Layer Editor is changed.
- //
- // Arguments:
- // newState - The new visibile state of the Layer Editor.
- //
- // layout - The parent layout for the Layer Editor.
- //
- // Returns:
- // true - If the change of state is to be allowed.
- //
- // false - If the state change is rejected.
- //
- {
- int $result = true;
-
- // Defer these commands because this proc is called when the visibility
- // state is about to change. This proc must return true to accept
- // the state change. After this proc returns then restore the
- // panel focus and update the pref menu.
- //
- evalDeferred("restoreLastPanelWithFocus(); updatePrefsMenu()");
-
- return $result;
- }
-
- //
- // Description:
- // Create the Layer Editor UI.
- //
- {
- global string $gLayerEditorForm;
-
- // Create the Layer Editor.
- //
- createLayerEditor($gLayerEditorForm);
-
- // Update the Layer Editor.
- //
- updateLayerEditor();
- }
-